package com.example.park2212.merchant

import androidx.lifecycle.MutableLiveData
import com.example.lib_base.entity.MerchatBean
import com.example.lib_base.entity.MerchatBeanItem
import com.example.lib_base.mvvm.BaseViewModel
import com.example.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class MerchantViewModel@Inject constructor(val apiservice: ApiService):BaseViewModel() {

    val merchantSuccess = MutableLiveData<MerchatBean>()
    fun getMerchant(){
        httpRequest({
            apiservice.getMerchant()
        },merchantSuccess::postValue)
    }

    val getMerchantByIdSuccess = MutableLiveData<MerchatBeanItem>()
    fun getMerchantById(id:Int){
        httpRequest({
            apiservice.getMerchantById(id)
        },getMerchantByIdSuccess::postValue)
    }

    val approveSuccess = MutableLiveData<MerchatBeanItem>()
    fun approve(id:Int){
        httpRequest({
            apiservice.approve(id)
        },approveSuccess::postValue)
    }

    fun reject(id:Int){
        httpRequest({
            apiservice.reject(id)
        },approveSuccess::postValue)
    }

    val merchantAddSuccess = MutableLiveData<MerchatBeanItem>()
    fun merchantAdd(item: MerchatBeanItem){
        httpRequest({
            apiservice.merchantAdd(mapToBody(item))
        },merchantAddSuccess::postValue)
    }
}